<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        敏感词替换测试
    </div>
    <div class="word">
        ,,bad,idghgjkdbadwordsfs
    </div>

</body>

<script>
    var badwords=["bad","badword"];

    var wordDom=document.querySelector(".word");

    var text=wordDom.innerText;

    text.includes("bad");//判断字符串中是否包含某个字符，有返回true，无返回false
    
    for(var i=0;i<badwords.length;i++){
        while (text.indexOf(badwords[i])!=-1){
            text=text.replace(badwords[i],"***");
            wordDom.innerText=text;
        }


    }
</script>
</html>